package stud.mpgame.net.command;

import org.slf4j.LoggerFactory;

import org.apache.mina.core.buffer.IoBuffer;

import stud.mpgame.network.Message;
import stud.mpgame.network.UserObject;

import stud.mpgame.network.util.MessageUtils;

import stud.mpgame.snapshot.ICommand;
import stud.mpgame.snapshot.ISnapshot;

/**
 * Created by IntelliJ IDEA.
 * User: Yarik
 */
public class ReadyToGameCommand extends UserObject implements ICommand {

    private final static org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ReadyToGameCommand.class);

    private int time;
    private String nickname;
    private int userID;

    public int getTime() {
       return time;
    }

    public int getUserID() {
        return userID;
    }

    public String getNickname() {
        return nickname;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public void apply(ISnapshot snapshot) {
        LOGGER.info("Player ready!");
    }

    @Override
    public void readExternal(IoBuffer buffer, Message owner) {
        this.time = buffer.getInt();
        this.nickname = MessageUtils.bytesToStr(buffer);
        this.userID = buffer.getInt();
    }

    @Override
    public String toString() {
        String result = "\n";
        result += "time: " + time + "\n";
        result += "nickname: " + nickname + "\n";
        result += "UserID: " + userID + "\n";
        return result;
    }

}
